home *** CD-ROM | disk | FTP | other *** search
- Path: noc.netcom.net!news
- From: Sean Palmer <sean@delta.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Linked lists - will this work?
- Date: Tue, 09 Apr 1996 15:50:53 -0400
- Organization: deltaComm Development, Inc.
- Message-ID: <316ABF9D.27B6@delta.com>
- References: <internews46BA23486F@argonet.co.uk>
- NNTP-Posting-Host: landspeeder.delta.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 3.0B2 (Win95; I)
-
- > If I implemented a new member fn for dllist along the lines of:
- >
- > void dllist::iterate(T (*fptr)(T))
- > {
- > node<T> *temp;
- > temp=getstart();
- > while(temp)
- > {
- > temp->change(f(temp->getinfo));
- > temp=temp->next;
- > }
- > }
- >
- > Would that have the effect I require, of taking a function which takes a T
- > as its argument and performing that over the list? If it would do that,
- > would it be reasonable 'safe' to use it also for functions that do not
- > actually change the data in their body, but return the value passed after,
- > say, printing it?
-
- No, try:
-
- void dllist::iterate(void (*func)(T&)) {
- node<T> *temp=start;
- while(temp) {
- func(temp->data);
- temp=temp->next;
- }
- }
-